<include file="public@header" />
</head>

<body>
    <div class="wrap">
        <ul class="nav nav-tabs">
            <li class=""><a href="{:url('life/index',array('id'=>$id))}">生活费发放</a></li>
            <li class="active"><a>新增条目</a></li>
        </ul>
        <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('life/doadd')}"
            enctype="multipart/form-data">


            <!-- <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    <span class="form-required">*</span>姓名
                </label>
                <div class="col-md-6 col-sm-10">

                    <select name="name" class="form-control">
                        <option value=""></option>
                        <volist name="leader" id="v">
                            <option value="{$v.id}" >{$v.name}</option>
                        </volist>
                    </select>
                </div>
            </div> -->

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    姓名
                </label>
                <div class="col-md-6 col-sm-10">
                    <select name="lid" id="nameSelect" class="form-control">
                        <option value=""></option>
                        <volist name="leader" id="v">
                            <option value="{$v.id}" data-type="{$v['type']}">{$v['name']}</option>
                        </volist>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    班组
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" id="teamDisplay" class="form-control" readonly>
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    <span class="form-required">*</span>支付方式
                </label>
                <div class="col-md-6 col-sm-10">
                    <select name="status" class="form-control">
                        <option value=""></option>
                        <option value="1">备用金</option>
                        <option value="2">公司付</option>
                    </select>
                </div>
            </div>


            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    <span class="form-required">*</span>金额
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="number" class="form-control" name="price">
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    <span class="form-required">*</span>支付时间
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="date" class="form-control" name="payDate">
                </div>
            </div>

            <input type="hidden" name="eid" value="{$id}">

            <!-- <div class="form-group">

            <label for="js-smtpsecure" class="col-sm-2 control-label">单据
            </label>
            <div class="col-md-6 col-sm-10">
                <input type="file" name="img[]" multiple/>
            </div>
        </div> -->

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">单据图
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="file" id="imgUpload" name="img[]" multiple accept="image/*" />
                    <div id="imgPreviewContainer" class="image-preview-container"
                        style="margin-top: 10px; display: flex; flex-wrap: wrap;"></div>
                </div>
            </div>

            <input type="hidden" name="type" value="1">



            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                    <a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
                </div>
            </div>
        </form>
    </div>
    <script src="__STATIC__/js/admin.js"></script>
    <script src="__STATIC__/js/image-uploader.js"></script>
    <script>
        // 页面加载时初始化班组
        function initializeTeamDisplay() {
            const nameSelect = document.getElementById('nameSelect');
            const selectedOption = nameSelect.options[nameSelect.selectedIndex];
            if (selectedOption) {
                const typeValue = selectedOption.getAttribute('data-type');
                const teamDisplay = document.getElementById('teamDisplay');
                teamDisplay.value = typeValue || ''; // 设置班组输入框的值
            }
        }

        // 姓名选择框联动班组
        document.getElementById('nameSelect').addEventListener('change', function () {
            const selectedOption = this.options[this.selectedIndex];
            if (selectedOption) {
                const typeValue = selectedOption.getAttribute('data-type');
                const teamDisplay = document.getElementById('teamDisplay');
                teamDisplay.value = typeValue || ''; // 设置班组输入框的值
            }
        });

        // 页面加载完成后初始化图片上传组件
        document.addEventListener('DOMContentLoaded', function () {
            // 初始化单据图上传组件
            const imgUploader = new ImageUploader({
                inputId: 'imgUpload',
                previewContainerId: 'imgPreviewContainer',
                fieldName: 'img',
                useDataTransfer: true
            });
        });
    </script>
</body>

</html>